<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <section id="app">
      <header>
        <h1>todo-List</h1>
        <input
          autofocus="autofocus"
          autocomplete="off"
          placeholder="请输入任务"
          v-model="inputValue"
          @keyup.enter="addList"
        />
      </header>
      <section v-show="remaining>0">
        <ul>
          <li v-for="(item,index) in todolist" :key="index">
            <span>{{index+1}}</span>
            <label>{{item}}</label>
            <button @click="remove(index)">删除</button>
          </li>
        </ul>
      </section>
      <footer v-show="remaining>0">
        <span><strong>{{remaining}}</strong>item left</span>
        <button @click="clear">Clear</button>
      </footer>
    </section>
    <script src="../lib/vue.js"></script>
    <script>
      new Vue({
        el: '#app',
        data: {
          todolist: ['a', 'v', 'd'],
          inputValue: 'new',
        },
        methods: {
          addList: function () {
            this.todolist.push(this.inputValue)
          },
          remove: function (index) {
            this.todolist.splice(index, 1)
          },
          clear: function () {
            this.todolist = []
          },
        },
        computed: {
          remaining: function () {
            return this.todolist.length
          },
        },
      })
    </script>
  </body>
</html>
